package 面试;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();//题目的数量
        int[] scorePerSubject = new int[n];
        for (int i = 0; i < n; i++) {
            scorePerSubject[i] = scanner.nextInt();
        }
        int[] timePerSubject = new int[n];
        for (int i = 0; i < n; i++) {
            timePerSubject[i] = scanner.nextInt();
        }
        int deadLine = scanner.nextInt();
        int maxScore = 0;
        // 1. find all possible time array
        List<List<Integer>> timeArray = getTimeArray(timePerSubject, deadLine, 0, new ArrayList<>(), new ArrayList<>());
        // 2. get maxScore
        maxScore = maxScore(timeArray, scorePerSubject);
        System.out.println(maxScore);
    }

    public static int maxScore(List<List<Integer>> timeArray, int[] scorePerSubject) {
        Iterator iterator = timeArray.iterator();
        int maxScore = 0;
        while (iterator.hasNext()) {
            List<Integer> list = (List<Integer>) iterator.next();
            int temp = 0;
            for (Integer index : list) {
                scorePerSubject[index] += temp;
            }
            maxScore = Math.max(maxScore, temp);
        }
        return maxScore;
    }

    public static List<List<Integer>> getTimeArray(int[] timePerSubject, int deadLine, int tempSumTime,
                                            List<List<Integer>> timeArray, List<Integer> tempList) {
        if (deadLine >= tempSumTime) {
            timeArray.add(new ArrayList<>(tempList));
        }

        for (int i = 0; i < timePerSubject.length; i++) {
            if (timeArray.contains(tempList)) {
                continue;
            } else {
                tempList.add(timePerSubject[i]);
                getTimeArray(timePerSubject, deadLine, timePerSubject[i]+tempSumTime,
                        timeArray, tempList);
                timeArray.remove(timeArray.size() - 1);
            }
        }
        return timeArray;
    }
}
